package cn.zcj.studytest.controller;

import cn.zcj.studytest.ThrowData.Result;
import cn.zcj.studytest.anno.LoginUser;
import cn.zcj.studytest.domain.Image;
import cn.zcj.studytest.domain.SignUp;
import cn.zcj.studytest.dto.CommentInsertDTO;
import cn.zcj.studytest.dto.CommentQueryDTO;
import cn.zcj.studytest.service.CommentService;
import cn.zcj.studytest.service.InsertContentService;
import cn.zcj.studytest.vo.CommentVO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/admin/comment")
@Slf4j
public class CommentController {
    @Resource
    private CommentService commentService;

    @PostMapping(value = "insertComment")
    public Result insertComment(@RequestBody CommentInsertDTO commentInsertDTO){
        Result result = new Result();
        try {
            return commentService.insertComment(commentInsertDTO);
        }catch (Exception e){
            result.setMsg("获取失败");
            result.setSuccess(false);
            return result;
        }
    }

    @PostMapping(value = "queryComment")
    public Result<List<CommentVO>> queryComment(@RequestBody CommentQueryDTO commentQueryDTO){
        Result<List<CommentVO>> result = new Result<>();
        try {
            return commentService.queryComment(commentQueryDTO);
        }catch (Exception e){
            result.setMsg("获取失败");
            result.setSuccess(false);
            return result;
        }
    }

    @PostMapping(value = "queryCommentSingle")
    @LoginUser
    public Result<CommentVO> queryCommentSingle(@RequestBody CommentQueryDTO commentQueryDTO, Long loginUserId){
        Result<CommentVO> result = new Result<>();
        try {
            commentQueryDTO.setCreateUserId(loginUserId);
            return commentService.queryCommentSingle(commentQueryDTO);
        }catch (Exception e){
            result.setMsg("获取失败");
            result.setSuccess(false);
            return result;
        }
    }

}
